package com.ruoyi.web.controller.system;

import java.util.Date;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HatchetAppVersion;
import com.ruoyi.system.service.IHatchetAppVersionService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * APP版本管理 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-03-18
 */
@Controller
@RequestMapping("/system/hatchetAppVersion")
public class HatchetAppVersionController extends BaseController
{
    private String prefix = "system/hatchetAppVersion";
	
	@Autowired
	private IHatchetAppVersionService hatchetAppVersionService;
	
	@RequiresPermissions("system:hatchetAppVersion:view")
	@GetMapping()
	public String hatchetAppVersion()
	{
	    return prefix + "/hatchetAppVersion";
	}
	
	/**
	 * 查询APP版本管理列表
	 */
	@RequiresPermissions("system:hatchetAppVersion:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(HatchetAppVersion hatchetAppVersion)
	{
		startPage();
        List<HatchetAppVersion> list = hatchetAppVersionService.selectHatchetAppVersionList(hatchetAppVersion);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出APP版本管理列表
	 */
	@RequiresPermissions("system:hatchetAppVersion:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HatchetAppVersion hatchetAppVersion)
    {
    	List<HatchetAppVersion> list = hatchetAppVersionService.selectHatchetAppVersionList(hatchetAppVersion);
        ExcelUtil<HatchetAppVersion> util = new ExcelUtil<HatchetAppVersion>(HatchetAppVersion.class);
        return util.exportExcel(list, "hatchetAppVersion");
    }
	
	/**
	 * 新增APP版本管理
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存APP版本管理
	 */
	@RequiresPermissions("system:hatchetAppVersion:add")
	@Log(title = "APP版本管理", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(HatchetAppVersion hatchetAppVersion)
	{		
		hatchetAppVersion.setId(StringUtils.randomUUID());
		hatchetAppVersion.setUpdateUser(getLoginName());
		hatchetAppVersion.setStatus("10A");//默认为启用状态
		hatchetAppVersion.setCreateTime(new Date());
		return toAjax(hatchetAppVersionService.insertHatchetAppVersion(hatchetAppVersion));
	}

	/**
	 * 修改APP版本管理
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		HatchetAppVersion hatchetAppVersion = hatchetAppVersionService.selectHatchetAppVersionById(id);
		mmap.put("hatchetAppVersion", hatchetAppVersion);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存APP版本管理
	 */
	@RequiresPermissions("system:hatchetAppVersion:edit")
	@Log(title = "APP版本管理", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(HatchetAppVersion hatchetAppVersion)
	{		
		return toAjax(hatchetAppVersionService.updateHatchetAppVersion(hatchetAppVersion));
	}
	
	
	/**
	 * APP版本状态修改
	 */
	@RequiresPermissions("system:hatchetAppVersion:edit")
	@Log(title = "APP版本管理", businessType = BusinessType.UPDATE)
	@PostMapping("/changeStatus")
	@ResponseBody
	public AjaxResult changeStatus(HatchetAppVersion hatchetAppVersion)
	{		
		return toAjax(hatchetAppVersionService.updateHatchetAppVersion(hatchetAppVersion));
	}
	/**
	 * 删除APP版本管理
	 */
	@RequiresPermissions("system:hatchetAppVersion:remove")
	@Log(title = "APP版本管理", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(hatchetAppVersionService.deleteHatchetAppVersionByIds(ids));
	}
	
}
